﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Base;

namespace Lamex.SIESystemManager.UI
{
    public partial class frmBIEShowList : DevExpress.XtraEditors.XtraForm
    {
        
        public frmBIEShowList(string DrawNumber,string TableName, List<string> strProcessList)
        {
            
            InitializeComponent();
            
            this.StartPosition = FormStartPosition.Manual;
            this.Location = new Point(SystemInformation.WorkingArea.Width - this.Width, SystemInformation.WorkingArea.Height - this.Height); 

            DataTable dt = BaseBuildSql.GetDataSetBySql(@"SELECT
                                                    A.name AS table_name,
                                                    B.name AS column_name,
                                                    C.value AS column_description
                                                    FROM LamexMESManager.sys.tables A
                                                    INNER JOIN LamexMESManager.sys.columns B ON B.object_id = A.object_id
                                                    LEFT JOIN LamexMESManager. sys.extended_properties C ON C.major_id = B.object_id AND C.minor_id = B.column_id
                                                    WHERE A.name = '" + TableName + "'").Tables[0];
            this.Text = "图纸号：" + DrawNumber + "保存清单";
            DataTable dtItems = dt.Clone() ;
            foreach (string str in strProcessList)
            {
                if (string.IsNullOrEmpty(str)) continue;
                DataRow[] drows = dt.Select("column_name like '%" + str + "%'");
                foreach(DataRow dr in drows)
                {
                    DataRow row= dtItems.NewRow();
                    row.ItemArray = dr.ItemArray;
                    dtItems.Rows.Add(row);
                }
            }
            
            DataTable dttemp = BaseBuildSql.GetDataSetBySql("select * from LamexMESManager.[dbo]." + TableName + "  where DRAWING_NUMBER='" + DrawNumber + "' ").Tables[0];

            //string line = "";
            if (dttemp.Rows.Count != 0)
            {
                foreach (DataRow row in dtItems.Rows)
                {

                    if (!string.IsNullOrEmpty(dttemp.Rows[0][row["column_name"].ToString()].ToString()))
                    {
                        //line = row["column_description"].ToString() + ":" + dttemp.Rows[0][row["column_name"].ToString()].ToString()+"\r\n";
                        if (!string.IsNullOrEmpty(dttemp.Rows[0][row["column_name"].ToString()].ToString()) )
                        {
                            if (dttemp.Rows[0][row["column_name"].ToString()].ToString() != "0")
                            {
                                string line = row["column_description"].ToString() + ":" + dttemp.Rows[0][row["column_name"].ToString()].ToString();
                                lstBoxShow.Items.Add(line);
                            }
                        }
                    }
                }

            }
                //XtraMessageBox.Show(line);
            
        }
        public DialogResult dialogResult; 
        private void frmBIEShowList_FormClosing(object sender, FormClosingEventArgs e)
        {

            //dialogResult = XtraMessageBox.Show("是否要保存数据？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); 

        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            dialogResult = DialogResult.Yes;
            this.Close();
        }

        private void btnColse_Click(object sender, EventArgs e)
        {
            dialogResult = DialogResult.No;
            this.Close();
        }
    }
}